package com.haiheng.library_base.db
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.RawQuery
import androidx.room.Update
import androidx.sqlite.db.SimpleSQLiteQuery
import androidx.sqlite.db.SupportSQLiteQuery

/**
 *
 * @Des:
 * @Author: hwz
 * @Date:2023/7/17 0017
 * @Version: 1.0
 */
@Dao
interface BookInfoDao {
    @Query("SELECT * FROM book_info")
    fun getAllBookInfo(): List<BookInfoBean>

    @Query("SELECT * FROM book_info WHERE id = :id")
    fun getBookInfoById(id: Int): BookInfoBean

    @Query("SELECT * FROM book_info WHERE barCode = :barCode")
    fun getBookInfoByBarCode(barCode: String): BookInfoBean

    @Query("SELECT * FROM book_info WHERE invertoryInfoStatus = :invertoryInfoStatus")
    fun getBookInfoByInvertoryInfoStatus(invertoryInfoStatus: Int): List<BookInfoBean>

    @Query("SELECT * FROM book_info WHERE fixedContainerSubId = :fixedContainerSubId")
    fun getBookInfoByfixedContainerSubId(fixedContainerSubId: Int): List<BookInfoBean>

    @Query("SELECT * FROM book_info WHERE misShelvedStatus IN(:misShelvedStatus)")
    fun getBookInfoByMisShelvedStatus(misShelvedStatus:Int): List<BookInfoBean>
    @Query("SELECT * FROM book_info WHERE currentContainerSub LIKE '%' || :containerSubCode || '%'")
    fun getBookInfoListByContainerSubCode(containerSubCode: String): List<BookInfoBean>
    @RawQuery
    fun getBookInfoListByCondition(query: SupportSQLiteQuery): List<BookInfoBean>
    fun getBookInfoListByLikeCondition(conditionName: String, searchKeyword: String): List<BookInfoBean> {
        val queryString = SimpleSQLiteQuery(
            "SELECT * FROM book_info WHERE $conditionName LIKE '%' || ? || '%'",
            arrayOf(searchKeyword)
        )
        return getBookInfoListByCondition(queryString)
    }

    fun getBookInfoListByCondition(conditionName: String, searchKeyword: String): List<BookInfoBean> {
        val queryString = SimpleSQLiteQuery(
            "SELECT * FROM book_info WHERE $conditionName = ?",
            arrayOf(searchKeyword)
        )
        return getBookInfoListByCondition(queryString)
    }
    @Query("SELECT * FROM book_info WHERE json_extract(currentContainerSub, '$.id') = :currentContainerSubId")
    fun getBookInfoListByCurrentContainerSubId(currentContainerSubId: Int): List<BookInfoBean>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertBookInfo(bookInfo: BookInfoBean)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertBookInfo(vararg bookInfos: BookInfoBean)

    @Update
    fun updateBookInfo(bookInfo: BookInfoBean)
    @Update
    fun updateBookInfo(vararg bookInfos: BookInfoBean)
    // 其他查询和更新操作...
}
